<template>
  <div class="app-container">
    <div class="app-title">查询条件</div>
    <div class="filter-container clearfix">
      <div class="searchItem">
        <label for="">工具名称</label>
        <el-input
          v-model="searchForm.toolName"
          class="search-item"
          maxlength="20"
          @keyup.enter.native="search"
        />
      </div>
      <div class="searchItem">
        <label for="">开放时间</label>
        <el-date-picker
          v-model="dateTime"
          :range-separator="null"
          start-placeholder="开放时间"
          value-format="yyyy-MM-dd"
          class="search-item date-range-item"
          type="daterange"
        />
      </div>
      <div class="searchItem">
        <label for="">工具状态 :</label>
        <el-select v-model="searchForm.status" placeholder="全部" filterable>
          <el-option label="已开放" value="0" />
          <el-option label="未开放" value="1" />
        </el-select>
      </div>
      <div class="searchItem">
        <label for="">平台名称:</label>
        <el-select v-model="searchForm.application" placeholder="全部">
          <el-option label="ebroker" value="00" />
          <el-option label="车E家" value="01" />
          <!-- <el-option label="车E家小程序" value="02" /> -->
        </el-select>
      </div>
      <div class="searchItem">
        <el-button
          v-hasPermission="['valuation:search']"
          class="searchItembtn"
          type="primary"
          @click="search"
        >
          {{ $t("common.search") }}
        </el-button>
        <el-button class="searchItembtn" type="success" @click="reset">
          {{ $t("table.reset") }}
        </el-button>
        <el-button class="searchItembtn" type="success" @click="add">
          新增工具
        </el-button>
      </div>
    </div>
    <div class="app-title">工具箱列表</div>

    <el-table
      ref="table"
      :key="tableKey"
      v-loading="loading"
      :data="list"
      border
      fit
      style="width: 100%"
    >
      <el-table-column
        label="工具箱编号"
        prop="id"
        :show-overflow-tooltip="true"
        align="center"
        min-width="80px"
      />
      <el-table-column
        label="工具名称"
        :show-overflow-tooltip="true"
        align="center"
        min-width="150px"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.toolName }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="分类名称"
        :show-overflow-tooltip="true"
        align="center"
        min-width="150px"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.platform == 0">{{
            ["车况估价", "服务保障", "必备工具", "维修工具", "辅助工具"][
              scope.row.classifyType
            ]
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="分类优先级"
        :show-overflow-tooltip="true"
        align="center"
        prop="priority"
        min-width="80px"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.platform == 0">{{ scope.row.priority }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="常用优先级"
        :show-overflow-tooltip="true"
        align="center"
        prop="usePriority"
        min-width="80px"
      />
      <el-table-column
        label="工具"
        :show-overflow-tooltip="true"
        align="center"
        min-width="150px"
      >
        <template slot-scope="scope">
          已开放:
          <a style="color: #00f" @click="openView(scope.row.imageUrlOpen)">{{
            scope.row.imageUrlOpen
          }}</a>
          <br>
          未开放:<a
            style="color: #00f"
            @click="openView(scope.row.imageUrlClose)"
          >{{ scope.row.imageUrlClose }}</a>
        </template>
      </el-table-column>
      <el-table-column
        label="跳转链接"
        :show-overflow-tooltip="true"
        align="center"
        min-width="150px"
      >
        <template slot-scope="scope">
          <a :href="scope.row.hrefUrl" target="_black" style="color: #00f">{{
            scope.row.hrefUrl
          }}</a>
        </template>
      </el-table-column>
      <el-table-column
        label="创建人"
        :show-overflow-tooltip="true"
        align="center"
        min-width="150px"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.createUser }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="开放时间"
        :show-overflow-tooltip="true"
        align="center"
        min-width="150px"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.createTime }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="平台名称"
        :show-overflow-tooltip="true"
        align="center"
        min-width="100px"
      >
        <template slot-scope="scope">
          <span>{{
            scope.row.application === "00"
              ? "erboker"
              : scope.row.application === "01"
                ? "车E家"
                : "车E家小程序"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="工具状态"
        :show-overflow-tooltip="true"
        align="center"
        min-width="80px"
      >
        <template slot-scope="scope">
          <span>{{ ["已开放", "未开放"][scope.row.status] }}</span>
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('table.operation')"
        align="center"
        min-width="150px"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="{ row }">
          <el-link class="el-icon-view" @click="edit(row)"> 编辑 </el-link>
          <el-link class="el-icon-close" @click="updateStatus(row)">
            {{ row.status == 0 ? "关闭" : "开放" }}
          </el-link>
          <el-link
            v-show="
              ['调表查询','延保服务','理赔记录','维保记录','诊断记录','调表查询','车辆检测','延保服务','VIN码查询',].includes(row.toolName)
            "
            class="el-icon-setting"
            @click="setting(row)"
          >
            价格
          </el-link>

          <el-link v-has-no-permission="['usercenter:view']" class="no-perm">
            {{ $t("tips.noPermission") }}
          </el-link>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="pagination.pageNum"
      :limit.sync="pagination.pageSize"
      @pagination="search"
    />
    <!-- 新增工具 -->
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :visible.sync="dialogVisible"
      width="40%"
      @close="myclose"
    >
      <el-form
        ref="ruleForm"
        :model="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="平台名称">
          <el-select v-model="ruleForm.application" placeholder="">
            <el-option key="1" label="车E家" value="01" checked />
            <el-option key="0" label="ebroker" value="00" />
          </el-select>
        </el-form-item>
        <el-form-item label="工具名称" required="">
          <el-input
            v-model="ruleForm.toolName"
            style="width: 300px"
            placeholder="请输入工具名称"
          />
        </el-form-item>
        <el-form-item v-if="ruleForm.application == '00'" label="分类名称">
          <el-select v-model="ruleForm.classifyType" placeholder="全部">
            <el-option label="车况估价" value="0" />
            <el-option label="服务保障" value="1" />
            <el-option label="必备工具" value="2" />
            <el-option label="维修工具" value="3" />
            <el-option label="辅助工具" value="4" />
          </el-select>
        </el-form-item>
        <el-form-item
          v-if="ruleForm.application == '00'"
          label="分类优先级"
          required=""
        >
          <el-input
            v-model="ruleForm.priority"
            style="width: 300px"
            max-length="99"
            type="text"
            onkeyup="value=value.replace(/[^\d]/g,'')"
            placeholder="请输入分类优先级"
          />
        </el-form-item>
        <el-form-item
          v-if="ruleForm.application == '00'"
          label="常用工具"
          required=""
        >
          <el-radio v-model="ruleForm.isUse" label="1" checked>是</el-radio>
          <el-radio v-model="ruleForm.isUse" label="0">否</el-radio>
          <br>
          <label v-if="ruleForm.isUse == 1" for="">常用优先级:</label>
          <el-input
            v-if="ruleForm.isUse == 1"
            v-model="ruleForm.usePriority"
            type="text"
            onkeyup="value=value.replace(/[^\d]/g,'')"
            max-length="99"
            placeholder="请输入优先级"
            style="width: 300px"
          />
        </el-form-item>
        <el-form-item
          v-if="ruleForm.application == '01'"
          label="常用优先级"
          required=""
        >
          <el-input
            v-model="ruleForm.usePriority"
            type="text"
            onkeyup="value=value.replace(/[^\d]/g,'')"
            max-length="99"
            placeholder="请输入优先级"
            style="width: 300px"
          />
        </el-form-item>
        <el-form-item label="工具icon" required="">
          <div style="display: flex; margin-bottom: 5px">
            <label for="">已开放</label>
            <el-upload
              style="
                border: 1px dashed #ccc;
                margin-left: 5px;
                border-radius: 5px;
              "
              class="avatar-uploader"
              :show-file-list="false"
              :on-success="handleAvatarSuccess1"
              :headers="headers"
              :action="baseUrlOpen"
            >
              <img v-if="imageUrl1" :src="imageUrl1" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon" />
            </el-upload>
          </div>
          <div style="display: flex">
            <label for="">未开放</label>
            <el-upload
              style="
                border: 1px dashed #ccc;
                margin-left: 5px;
                border-radius: 5px;
              "
              class="avatar-uploader"
              :headers="headers"
              :action="baseUrlClose"
              :show-file-list="false"
              :on-success="handleAvatarSuccess2"
            >
              <img v-if="imageUrl2" :src="imageUrl2" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon" />
            </el-upload>
          </div>
        </el-form-item>
        <el-form-item label="跳转链接" prop="resource">
          <el-input
            v-model="ruleForm.hrefUrl"
            style="width: 300px"
            placeholder="请输入跳转地址"
          />
        </el-form-item>
        <!-- <el-form-item label="支付方式" required="">
          <el-radio v-model="ruleForm.payType" label="0">积分</el-radio>
          <el-radio v-model="ruleForm.payType" label="1">现金</el-radio>
          <br>
          <label v-if="ruleForm.payType == 0" for="">积分价格:</label>
          <label v-else for="">现金价格:</label>
          <el-input
            v-model.number="ruleForm.price"
            type="number"
            style="width: 300px"
            @blur="onBlur"
          />
          <br>
          <br>
          <label for="">赠送积分:</label>
          <el-input
            v-model="ruleForm.presenterIntegral"
            type="number"
            style="width: 300px"
          />
        </el-form-item> -->
        <el-form-item v-if="ruleForm.application == '01'" label="加V优推">
          <el-radio v-model="ruleForm.plusV" label="0">否</el-radio>
          <el-radio v-model="ruleForm.plusV" label="1">是</el-radio>
        </el-form-item>
        <el-form-item label="工具状态">
          <el-radio v-model="ruleForm.status" label="0">已开放</el-radio>
          <el-radio v-model="ruleForm.status" label="1">未开放</el-radio>
        </el-form-item>
        <el-form-item>
          <el-button @click="back">返回</el-button>
          <el-button
            type="primary"
            @click="submitForm('ruleForm')"
          >确认提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- 编辑工具 -->
    <el-dialog
      title="编辑工具"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :visible.sync="editdialogVisible"
      width="40%"
    >
      <el-form
        ref="ruleForm"
        :model="editForm"
        label-width="100px"
        class="demo-editForm"
      >
        <el-form-item label="平台名称">
          <el-select v-model="editForm.application" placeholder="">
            <el-option key="1" label="车E家" :value="'01'" />
            <el-option key="0" label="ebroker" :value="'00'" />
          </el-select>
        </el-form-item>
        <el-form-item label="工具名称" required="">
          <el-input
            v-model="editForm.toolName"
            style="width: 300px"
            placeholder="请输入工具名称"
          />
        </el-form-item>

        <el-form-item v-if="editForm.application == '00'" label="分类名称">
          <el-select v-model="editForm.classifyType" placeholder="全部">
            <el-option label="车况估价" value="0" />
            <el-option label="服务保障" value="1" />
            <el-option label="必备工具" value="2" />
            <el-option label="维修工具" value="3" />
            <el-option label="辅助工具" value="4" />
          </el-select>
        </el-form-item>
        <el-form-item
          v-if="editForm.application === '00'"
          label="分类优先级"
          required=""
        >
          <el-input
            v-model="editForm.priority"
            style="width: 300px"
            max-length="99"
            type="text"
            onkeyup="value=value.replace(/[^\d]/g,'')"
            placeholder="请输入分类优先级"
          />
        </el-form-item>
        <el-form-item
          v-if="editForm.application == '00'"
          label="常用工具"
          prop="usePriority"
          required=""
        >
          <el-radio v-model="editForm.isUse" label="1">是</el-radio>
          <el-radio v-model="editForm.isUse" label="0">否</el-radio>
          <br>
          <label v-if="editForm.isUse == 1" for="">常用优先级:</label>
          <el-input
            v-if="editForm.isUse == 1"
            v-model="editForm.usePriority"
            type="text"
            onkeyup="value=value.replace(/[^\d]/g,'')"
            max-length="99"
            placeholder="请输入优先级"
            style="width: 300px"
          />
        </el-form-item>
        <el-form-item
          v-if="editForm.platform === '01'"
          label="常用优先级"
          required=""
        >
          <el-input
            v-model="editForm.usePriority"
            type="text"
            onkeyup="value=value.replace(/[^\d]/g,'')"
            max-length="99"
            placeholder="请输入优先级"
            style="width: 300px"
          />
        </el-form-item>
        <el-form-item label="工具icon" prop="type" required="">
          <div style="display: flex; margin-bottom: 5px">
            <label for="">已开放</label>
            <el-upload
              class="avatar-uploader"
              style="
                border: 1px dashed #ccc;
                margin-left: 5px;
                border-radius: 5px;
              "
              :show-file-list="false"
              :on-success="handleAvatarSuccess1"
              :headers="headers"
              :action="baseUrlOpen"
            >
              <img v-if="imageUrl1" :src="imageUrl1" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon" />
            </el-upload>
          </div>
          <div style="display: flex">
            <label for="">未开放</label>
            <el-upload
              style="
                border: 1px dashed #ccc;
                margin-left: 5px;
                border-radius: 5px;
              "
              class="avatar-uploader"
              :headers="headers"
              :action="baseUrlClose"
              :show-file-list="false"
              :on-success="handleAvatarSuccess2"
            >
              <img v-if="imageUrl2" :src="imageUrl2" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon" />
            </el-upload>
          </div>
        </el-form-item>
        <el-form-item label="跳转链接">
          <el-input
            v-model="editForm.hrefUrl"
            style="width: 300px"
            placeholder="请输入跳转地址"
          />
        </el-form-item>
        <!-- <el-form-item label="支付方式" required="">
          <el-radio v-model="editForm.payType" label="0">积分</el-radio>
          <el-radio v-model="editForm.payType" label="1">现金</el-radio>
          <br>
          <label v-if="editForm.payType == 0" for="">积分价格:</label>
          <label v-else for="">现金价格:</label>
          <el-input
            v-model="editForm.price"
            type="number"
            style="width: 300px"
            @blur="onEditBlur"
          />
          <br> <br>
          <label for="">赠送积分:</label>
          <el-input
            v-model="editForm.presenterIntegral"
            type="number"
            style="width: 300px"
          />
        </el-form-item> -->
        <el-form-item v-if="editForm.application == '01'" label="加V优推">
          <el-radio v-model="editForm.plusV" label="0">否</el-radio>
          <el-radio v-model="editForm.plusV" label="1">是</el-radio>
        </el-form-item>
        <el-form-item label="工具状态">
          <el-radio v-model="editForm.status" label="0">已开放</el-radio>
          <el-radio v-model="editForm.status" label="1">未开放</el-radio>
        </el-form-item>
        <el-form-item>
          <el-button @click="editdialogVisible = false">返回</el-button>
          <el-button
            type="primary"
            @click="submitFormEdit('editForm')"
          >确认提交</el-button>
        </el-form-item>
      </el-form>
      <p style="font-size: 20px; font-weight: 600; margin-bottom: 10px">
        修改记录
      </p>
      <el-table
        ref="table"
        :key="tableKey"
        v-loading="loading"
        :data="list1"
        border
        fit
        style="width: 100%"
      >
        <el-table-column
          label="修改时间"
          :show-overflow-tooltip="true"
          align="center"
          prop="createTime"
          min-width="80px"
        />
        <el-table-column
          label="修改人"
          :show-overflow-tooltip="true"
          align="center"
          min-width="150px"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.createUser }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="修改类型"
          :show-overflow-tooltip="true"
          align="center"
          min-width="150px"
        >
          <template slot-scope="scope">
            <span
              v-for="(item, i) in JSON.parse(scope.row.columnName)"
              :key="i"
            >
              {{ item.plusV }}
              {{ item.application }}
              {{ item.priority }}
              {{ item.toolName }}
              {{ item.classifyType }}
              {{ item.isUse }}
              {{ item.usePriority }}
              {{ item.imageUrlOpen }}
              {{ item.imageUrlClose }}
              {{ item.hrefUrl }}
              {{ item.status }}
              {{ item.payType }}
              {{ item.price }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          label="修改前"
          :show-overflow-tooltip="true"
          align="center"
          prop="columnValue"
          min-width="80px"
        >
          <template slot-scope="scope">
            <span
              v-for="(item, i) in JSON.parse(scope.row.columnValue)"
              :key="i"
            >
              {{
                item.plusV != null
                  ? `是否加V优推:${["否", "是"][item.plusV]}`
                  : ""
              }}
              {{
                item.application
                  ? `平台名称${item.application == "00" ? "erboker" : "车E家"},`
                  : ""
              }}
              {{ item.priority ? `工具排序优先级${item.priority},` : "" }}
              {{ item.toolName ? `工具名称:${item.toolName},` : "" }}
              {{ item.classifyType ? `分类类型\:${item.classifyType},` : "" }}
              {{ item.isUse ? `是否常用工具:${item.isUse},` : "" }}
              {{
                item.usePriority ? `常用工具排序优先级:${item.usePriority}` : ""
              }}
              {{ item.imageUrlOpen ? `工具开放图片:${item.imageUrlOpen}` : "" }}
              {{
                item.imageUrlClose ? `工具未开放图片:${item.imageUrlClose}` : ""
              }}
              {{ item.hrefUrl ? `跳转链接:${item.hrefUrl}` : "" }}
              {{
                item.status != null
                  ? `工具状态:${["已开放", "未开放"][item.status]}`
                  : ""
              }}
              {{ item.payType ? `支付方式:${item.payType},` : "" }}
              {{ item.price ? `价格:${item.price}` : "" }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          label="修改后"
          :show-overflow-tooltip="true"
          align="center"
          prop="columnValueAfter"
          min-width="80px"
        >
          <template slot-scope="scope">
            <span
              v-for="(item, i) in JSON.parse(scope.row.columnValueAfter)"
              :key="i"
            >
              {{
                item.plusV != null
                  ? `是否加V优推:${["否", "是"][item.plusV]}`
                  : ""
              }}
              {{
                item.application
                  ? `平台名称${item.application == "00" ? "erboker" : "车E家"},`
                  : ""
              }}
              {{ item.priority ? `工具排序优先级${item.priority},` : "" }}
              {{ item.toolName ? `工具名称:${item.toolName},` : "" }}
              {{ item.classifyType ? `分类类型\:${item.classifyType},` : "" }}
              {{ item.isUse ? `是否常用工具:${item.isUse},` : "" }}
              {{
                item.usePriority ? `常用工具排序优先级:${item.usePriority}` : ""
              }}
              {{ item.imageUrlOpen ? `工具开放图片:${item.imageUrlOpen}` : "" }}
              {{
                item.imageUrlClose ? `工具未开放图片:${item.imageUrlClose}` : ""
              }}
              {{ item.hrefUrl ? `跳转链接:${item.hrefUrl}` : "" }}
              {{
                item.status != null
                  ? `工具状态:${["已开放", "未开放"][item.status]}`
                  : ""
              }}
              {{ item.payType ? `支付方式:${item.payType},` : "" }}
              {{ item.price ? `价格:${item.price}` : "" }}
            </span>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total2 > 0"
        :total="total2"
        :page.sync="paginations.pageNum"
        :limit.sync="paginations.pageSize"
        @pagination="search2"
      />
    </el-dialog>
    <el-dialog title="" :visible.sync="viewDialogVisible" width="30%">
      <img :src="previewUrl" style="width: 100%">
    </el-dialog>
    <!-- 设置金额 -->
    <el-dialog
      title="价格设置"
      :visible.sync="editPricedialogVisible"
      width="50%"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form
        ref="ruleForm"
        :model="priceForm"
        label-width="100px"
        class="demo-editForm"
      >
        <el-form-item
          :label="
            toolName == '车辆检测'
              ? '事故排查检测'
              : toolName == '诊断记录' || toolName == '调表查询'
                ? '明睿价格'
                : '现金价格'
          "
        >
          <el-input
            v-model="priceForm.price"
            onkeyup="value=value.replace(/[^\d|^.]/g, '')"
            maxlength="8"
            style="width: 300px"
            placeholder="请输入现金价格"
            @blur="onBlur"
          />
        </el-form-item>
        <el-form-item v-if="toolName == '维保记录'" label="金额上浮赔率">
          <el-input
            v-model="priceForm.price4"
            onkeyup="value=value.replace(/[^\d|^.]/g, '')"
            maxlength="8"
            style="width: 300px"
            placeholder="请输入现金价格"
          />
        </el-form-item>

        <el-form-item v-if="toolName == '车辆检测'" label="重要部件检测">
          <el-input
            v-model="priceForm.price1"
            onkeyup="value=value.replace(/[^\d|^.]/g, '')"
            maxlength="8"
            style="width: 300px"
            placeholder="请输入现金价格"
            @blur="onBlur"
          />
        </el-form-item>
        <el-form-item v-if="toolName == '车辆检测'" label="全面检测">
          <el-input
            v-model="priceForm.price2"
            onkeyup="value=value.replace(/[^\d|^.]/g, '')"
            maxlength="8"
            style="width: 300px"
            placeholder="请输入现金价格"
            @blur="onBlur"
          />
        </el-form-item>
        <el-form-item
          v-if="application == '01' && plusV == 1"
          label="加V优推价格"
        >
          <el-input
            v-model="priceForm.plusVPrice"
            onkeyup="value=value.replace(/[^\d|^.]/g, '')"
            maxlength="8"
            style="width: 300px"
            placeholder="请输入现金价格"
            @blur="onBlur"
          />
        </el-form-item>

        <el-form-item>
          <el-button @click="editPricedialogVisible = false">返回</el-button>
          <el-button
            type="primary"
            @click="submitFormEdits()"
          >确认提交</el-button>
        </el-form-item>
      </el-form>
      <p style="font-size: 20px; font-weight: 600; margin-bottom: 10px">
        修改记录
      </p>
      <el-table
        ref="table"
        :key="tableKey"
        v-loading="loading"
        :data="list3"
        border
        fit
        style="width: 100%"
      >
        <el-table-column
          label="修改时间"
          :show-overflow-tooltip="true"
          align="center"
          prop="createTime"
          min-width="80px"
        />
        <el-table-column
          label="修改人"
          :show-overflow-tooltip="true"
          align="center"
          min-width="50px"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.createUser }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="修改前"
          :show-overflow-tooltip="true"
          align="center"
          prop="amount"
          min-width="120px"
        >
          <template slot-scope="scope">
            <span
              v-for="(item, i) in JSON.parse(scope.row.columnValue)"
              :key="i"
              style="width: 200px; display: inline-block; white-space: pre-line"
            >
              {{ item.amount }}
            </span>
          </template>
        </el-table-column>

        <el-table-column
          label="修改后"
          :show-overflow-tooltip="true"
          align="center"
          prop="columnValueAfter"
          min-width="120px"
        >
          <template slot-scope="scope">
            <span
              v-for="(item, i) in JSON.parse(scope.row.columnValueAfter)"
              :key="i"
              style="width: 200px; display: inline-block; white-space: pre-line"
            >
              {{ item.amount }}
            </span>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total3 > 0"
        :total="total3"
        :page.sync="paginations.pageNum"
        :limit.sync="paginations.pageSize"
        @pagination="search3"
      />
    </el-dialog>
    <!-- 延保服务设置金额  -->
    <el-dialog
      title="价格设置"
      :visible.sync="warrantydialogVisible"
      width="50%"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form
        ref="ruleForm"
        :model="priceForm"
        label-width="100px"
        class="myeditForm"
      >
        <table>
          <thead>
            <tr>
              <th style="width: 200px">套餐类型 / 级别车型</th>
              <th style="width: 150px">A级车</th>
              <th style="width: 150px">B级车</th>
              <th style="width: 150px">C级车</th>
              <th style="width: 150px">D级车</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td style="width: 200px; text-align: center">基础保修</td>
              <td v-for="item in jichu" :key="item.type">
                <el-input
                  v-model="item.amount"
                  onkeyup="value=value.replace(/[^\d|^.]/g, '')"
                  maxlength="8"
                  style="width: 150px"
                  placeholder="请输入价格"
                />
              </td>
            </tr>
            <tr>
              <td style="width: 200px; text-align: center">优选保修</td>
              <td v-for="item in youXuan" :key="item.type">
                <el-input
                  v-model="item.amount"
                  style="width: 150px"
                  onkeyup="value=value.replace(/[^\d|^.]/g, '')"
                  maxlength="8"
                  placeholder="请输入价格"
                />
              </td>
            </tr>
            <tr>
              <td style="width: 200px; text-align: center">综合保修</td>
              <td v-for="item in zhongHe" :key="item.type">
                <el-input
                  v-model="item.amount"
                  style="width: 150px"
                  maxlength="8"
                  onkeyup="value=value.replace(/[^\d|^.]/g, '')"
                  placeholder="请输入价格"
                />
              </td>
            </tr>
            <tr>
              <td style="width: 200px; text-align: center">全面保修</td>
              <td v-for="item in quanMian" :key="item.type">
                <el-input
                  v-model="item.amount"
                  style="width: 150px"
                  maxlength="8"
                  onkeyup="value=value.replace(/[^\d|^.]/g, '')"
                  placeholder="请输入价格"
                />
              </td>
            </tr>
          </tbody>
        </table>
        <el-form-item
          v-if="application == '01' && plusV == 1"
          label="加V优推价格"
        >
          <el-input
            v-model="priceForm.plusVPrice"
            onkeyup="value=value.replace(/[^\d|^.]/g, '')"
            maxlength="8"
            style="width: 300px"
            placeholder="请输入现金价格"
            @blur="onBlur"
          />
        </el-form-item>

        <el-form-item>
          <el-button @click="warrantydialogVisible = false">返回</el-button>
          <el-button
            type="primary"
            @click="warrantyFormEdits()"
          >确认提交</el-button>
        </el-form-item>
      </el-form>
      <p style="font-size: 20px; font-weight: 600; margin-bottom: 10px">
        修改记录
      </p>
      <el-table
        ref="table"
        :key="tableKey"
        v-loading="loading"
        :data="list4"
        border
        fit
        style="width: 100%"
      >
        <el-table-column
          label="修改时间"
          :show-overflow-tooltip="true"
          align="center"
          prop="createTime"
          min-width="80px"
        />
        <el-table-column
          label="修改人"
          :show-overflow-tooltip="true"
          align="center"
          min-width="50px"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.createUser }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="修改前"
          :show-overflow-tooltip="true"
          align="center"
          prop="amount"
          min-width="120px"
        >
          <template slot-scope="scope">
            <span
              v-for="(item, i) in JSON.parse(scope.row.columnValue)"
              :key="i"
              style="width: 200px; display: inline-block; white-space: pre-line"
            >
              {{ item.amount }}
            </span>
          </template>
        </el-table-column>

        <el-table-column
          label="修改后"
          :show-overflow-tooltip="true"
          align="center"
          prop="columnValueAfter"
          min-width="120px"
        >
          <template slot-scope="scope">
            <span
              v-for="(item, i) in JSON.parse(scope.row.columnValueAfter)"
              :key="i"
              style="width: 200px; display: inline-block; white-space: pre-line"
            >
              {{ item.amount }}
            </span>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total4 > 0"
        :total="total4"
        :page.sync="paginations1.pageNum"
        :limit.sync="paginations1.pageSize"
        @pagination="search4"
      />
    </el-dialog>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import crypto from 'crypto-js'
const appkey = 'Sz7Jo5M4T1smiHgS'
// eslint-disable-next-line radix
const timestamp = parseInt(Date.now() / 1000)
const nonceStr = 'HBxcnRjX'
export default {
  components: {
    Pagination
  },
  data() {
    return {
      list4: [],
      total4: 0,
      warrantydialogVisible: false,
      editPricedialogVisible: false,
      previewUrl: '',
      viewDialogVisible: false,
      title: '新增工具',
      baseUrlOpen:
        process.env.VUE_APP_BASE_API +
        '/web/upload/bigFile?source=web&type=active',
      baseUrlClose:
        process.env.VUE_APP_BASE_API +
        '/web/upload/bigFile?source=web&type=active',
      total: 0,
      total2: 0,
      dateTime: '',
      dialogVisible: false,
      editdialogVisible: false,
      imageUrl1: '',
      imageUrl2: '',
      searchForm: {
        toolName: '',
        startTime: '',
        endTime: '',
        status: '',
        application: ''
      },
      pagination: {
        pageSize: 10,
        pageNum: 1
      },
      loading: false,
      tableKey: 0,
      list: [],
      list1: [],
      ruleForm: {
        application: '01',
        priority: '',
        toolName: '',
        classifyType: '',
        isUse: '',
        usePriority: '',
        imageUrlOpen: '',
        imageUrlClose: '',
        payType: '1',
        status: '0',
        hrefUrl: '',
        plusV: ''
      },
      editForm: {
        application: '',
        priority: '',
        toolName: '',
        classifyType: '',
        isUse: '',
        usePriority: '',
        imageUrlOpen: '',
        imageUrlClose: '',
        payType: '',
        status: '',
        hrefUrl: '',
        plusV: ''
      },
      headers: {
        Authorization: ''
      },
      paginations: {
        pageSize: 5,
        pageNum: 1
      },
      paginations1: {
        pageNum: 1,
        pageSize: 5
      },
      myprice: '',
      priceForm: {
        price: '',
        price1: '',
        price2: '',
        price4: '',
        plusVPrice: ''
      },
      priceList: [],
      list3: [],
      total3: 0,
      toolId: 0,
      toolName: '',
      jichu: [{
        toolId: this.toolId,
        type: 104,
        amount: ''
      }, {
        toolId: this.toolId,
        type: 105,
        amount: ''
      }, {
        toolId: this.toolId,
        type: 106,
        amount: ''
      }, {
        toolId: this.toolId,
        type: 107,
        amount: ''
      }],
      youXuan: [{
        toolId: this.toolId,
        type: 108,
        amount: ''
      }, {
        type: 109,
        amount: '',
        toolId: this.toolId
      }, {
        toolId: this.toolId,
        type: 110,
        amount: ''
      }, {
        toolId: this.toolId,
        type: 111,
        amount: ''
      }],
      zhongHe: [{
        toolId: this.toolId,
        type: 112,
        amount: ''
      }, {
        type: 113,
        toolId: this.toolId,
        amount: ''
      }, {
        type: 114,
        toolId: this.toolId,
        amount: ''
      }, {
        type: 115,
        amount: ''
      }],
      quanMian: [{
        type: 116,
        toolId: this.toolId,
        amount: ''
      }, {
        type: 117,
        toolId: this.toolId,
        amount: ''
      }, {
        type: 118,
        toolId: this.toolId,
        amount: ''
      }, {
        type: 119,
        toolId: this.toolId,
        amount: ''
      }],
      plusVObjec: {
        type: 120,
        toolId: this.toolId,
        amount: ''
      },
      isFrist: false,
      application: '', // 平台
      plusV: 0,
      length: 0
    }
  },
  watch: {
    ruleForm: {
      handler(newVal) {
        if (newVal.priority > 99) {
          newVal.priority = ''
        }
        if (newVal.usePriority > 99) {
          newVal.usePriority = ''
        }
        // newVal.price =this.toDecimal2(newVal.price);
      },
      deep: true
    },
    editForm: {
      handler(newVal) {
        if (newVal.priority > 99) {
          newVal.priority = ''
        }
        if (newVal.usePriority > 99) {
          newVal.usePriority = ''
        }
        // newVal.price =this.toDecimal2(newVal.price);22
      },
      deep: true
    },
    jichu: {
      handler(newVal) {
        console.log(newVal)
      }
    }
  },
  created() {
    const temp = [appkey, timestamp, nonceStr, encodeURIComponent(this.baseUrlOpen)].sort()
    const myTemp = temp.join('')
    const hmacSHA256 = crypto.HmacSHA256(myTemp, '2ac16dc294046ed43a87d70ad8cb08013fab0b57')
    const signature = crypto.enc.Base64.stringify(hmacSHA256)
    const signs = `appkey=${appkey},timestamp=${timestamp},nonceStr=${nonceStr},sign=${signature},data=${encodeURIComponent(this.baseUrlOpen)}`
    const tokens = `${crypto.MD5(signs)}`
    this.headers = {
      Authorization: `bearer ${this.$store.state.account.accessToken}`,
      channel: '00',
      application: '02',
      source: 5,
      appkey,
      nonceStr,
      timestamp,
      sign: tokens

    }
    // this.headers.Authorization = `bearer ${this.$store.state.account.accessToken}`
    this.search()
  },
  methods: {
    myclose() {
      this.ruleForm = { payType: '1',
        platform: '1',
        status: '0' }
    },
    setting(row) {
      this.application = row.application
      console.log(this.application)
      this.plusV = row.plusV
      if (row.toolName === '延保服务') {
        this.toolId = row.id
        this.toolName = row.toolName
        this.fnWarranty(this.toolId)
        return
      }
      console.log(row)
      this.editPricedialogVisible = true
      this.toolId = row.id
      this.toolName = row.toolName
      this.priceList = []
      this.$post(
        '/web/operationLog/list',
        {
          queryRequest: {
            pageNum: this.paginations.pageNum,
            pageSize: this.paginations.pageSize,
            field: 'createTime',
            order: 'descending'
          },
          entity: {
            tableName: 'tools_amount',
            columnId: row.id
          }
        },
        'json'
      ).then((res) => {
        if (res.data.code === '0') {
          this.list3 = res.data.data.records
          this.total3 = res.data.data.total
        }
      })

      this.$get(`/web/toolsAmount/get?toolId=${this.toolId}`).then((res) => {
        console.log(res)
        if (res.data.code === '0') {
          // console.log(res.data.data[0].amount)
          if (res.data.data.length > 0) {
            this.priceForm.price = (res.data.data.find(item => item.type === 100)) ? res.data.data.find(item => item.type === 100).amount : (res.data.data.find(item => item.type === 101)) ? res.data.data.find(item => item.type === 101).amount : ''
            this.priceForm.price1 = (res.data.data[1] && res.data.data[1].amount) || ''
            this.priceForm.price2 =
              (res.data.data[2] && res.data.data[2].amount) || ''
            this.priceForm.price4 = res.data.data.find(item => item.type === 99) ? res.data.data.find(item => item.type === 99).amount : ''
            this.priceList = res.data.data
            // console.log(res.data.data.find(item=>item.type===120).amount)
            this.priceForm.plusVPrice = res.data.data.find(item => item.type === 120) ? res.data.data.find(item => item.type === 120).amount : ''
          } else {
            this.priceForm.price = ''
            this.priceList = []
          }

          console.log(this.priceList)
        }
      })
    },
    warrantyFormEdits() {
      console.log(this.toolId)
      let list = ''
      if (this.plusVObjec) {
        this.plusVObjec.amount = this.priceForm.plusVPrice
        list = [...this.jichu, ...this.quanMian, ...this.youXuan, ...this.zhongHe, this.plusVObjec]
      } else {
        list = [...this.jichu, ...this.quanMian, ...this.youXuan, ...this.zhongHe]
      }
      list.forEach(item => {
        item.toolId = this.toolId
      })
      if (Number(this.priceForm.plusVPrice) > 9999999.99) {
        return this.$message.error('金额应小于9999999.99')
      }
      if (this.isFrist || this.length === 1) { // 新增操作
        console.log(list)
        this.$post('/web/toolsAmount', list, 'json').then((res) => {
          if (res.data.code === '0') {
            this.warrantydialogVisible = false
            this.$message.success('价格设置成功')
          } else {
            this.$message.error(res.data.message)
          }
        })
      } else {
        this.$put('/web/toolsAmount', list, 'json').then((res) => {
          if (res.data.code === '0') {
            this.warrantydialogVisible = false
            this.$message.success('价格设置成功')
          } else {
            this.$message.error(res.data.message)
          }
        })
      }
    },
    fnWarranty(id) {
      this.warrantydialogVisible = true
      this.$post(
        '/web/operationLog/list',
        {
          queryRequest: {
            pageNum: this.paginations1.pageNum,
            pageSize: this.paginations1.pageSize,
            field: 'createTime',
            order: 'descending'
          },
          entity: {
            tableName: 'tools_amount',
            columnId: id
          }
        },
        'json'
      ).then((res) => {
        if (res.data.code === '0') {
          this.list4 = res.data.data.records
          this.total4 = res.data.data.total
        }
      })
      this.$get(`/web/toolsAmount/get?toolId=${id}`).then(res => {
        if (res.data.code === '0') {
          let list = []
          this.length = res.data.data.length
          if (res.data.data.length === 0) {
            console.log('第一次')
            this.isFrist = true
          } else {
            console.log('第二次')
            this.isFrist = false
            list = res.data.data
            this.priceForm.plusVPrice = list.find(item => item.type === 120) ? list.find(item => item.type === 120).amount : ''
            this.plusVObjec = list.find(item => item.type === 120)
            this.jichu.forEach(item => {
              const obj = list.find(items => items.type === item.type)
              item.amount = obj && obj.amount
              item.id = obj && obj.id
            })
            this.quanMian.forEach(item => {
              const obj = list.find(items => items.type === item.type)
              item.amount = obj && obj.amount
              item.id = obj && obj.id
            })
            this.youXuan.forEach(item => {
              const obj = list.find(items => items.type === item.type)
              item.amount = obj && obj.amount
              item.id = obj && obj.id
            })
            this.zhongHe.forEach(item => {
              const obj = list.find(items => items.type === item.type)
              item.amount = obj && obj.amount
              item.id = obj && obj.id
            })
          }
        }
      })
    },
    search4() {
      this.$post(
        '/web/operationLog/list',
        {
          queryRequest: {
            pageNum: this.paginations1.pageNum,
            pageSize: this.paginations1.pageSize,
            field: 'createTime',
            order: 'descending'
          },
          entity: {
            tableName: 'tools_amount',
            columnId: this.toolId
          }
        },
        'json'
      ).then((res) => {
        if (res.data.code === '0') {
          this.list4 = res.data.data.records
          this.total4 = res.data.data.total
        }
      })
    },
    search3() {
      this.$post(
        '/web/operationLog/list',
        {
          queryRequest: {
            pageNum: this.paginations.pageNum,
            pageSize: this.paginations.pageSize,
            field: 'createTime',
            order: 'descending'
          },
          entity: {
            tableName: 'tools_amount',
            columnId: this.toolId
          }
        },
        'json'
      ).then((res) => {
        if (res.data.code === '0') {
          this.list3 = res.data.data.records
          this.total3 = res.data.data.total
        }
      })
    },
    onEditBlur() {
      this.editForm.price = Number(this.editForm.price).toFixed(2)
    },
    onBlur() {
      // this.ruleForm.price = Number(this.ruleForm.price).toFixed(2)
      this.priceForm.price = Number(this.priceForm.price).toFixed(2)
      this.priceForm.price1 = Number(this.priceForm.price1).toFixed(2)
      this.priceForm.price2 = Number(this.priceForm.price2).toFixed(2)
      this.priceForm.plusVPrice = Number(this.priceForm.plusVPrice).toFixed(2)
    },
    openView(url) {
      this.previewUrl = url
      this.viewDialogVisible = true
    },
    add() {
      this.ruleForm.id = 0
      this.dialogVisible = true
      this.imageUrl1 = ''
      this.imageUrl2 = ''
    },
    async search(e) {
      if (e && e.page) {
        this.pagination.pageNum = e.page
        this.pagination.pageSize = e.limit
      }
      if (this.dateTime) {
        this.searchForm.startTime = `${this.dateTime[0]}  00:00`
        this.searchForm.endTime = `${this.dateTime[1]}  23:59`
      }
      this.loading = true
      try {
        // /web/reportBase/list/report?userNameOrMobile=13008800250&pageNum=1&pageSize=20
        const result = await this.$post(
          '/web/tools/list',
          {
            queryRequest: {
              ...this.pagination,
              field: 'createTime',
              order: 'descending'
            },
            entity: {
              ...this.searchForm
            }
          },
          'json'
        )
        if (result.data.code === '0') {
          this.loading = false
          this.list = result.data.data.records
          this.total = result.data.data.total
        }
      } catch (error) {
        this.loading = false
      }
    },
    submitForm(formName) {
      this.ruleForm.imageUrlOpen = this.imageUrl1
      this.ruleForm.imageUrlClose = this.imageUrl2
      if (this.ruleForm.toolName === '') {
        this.$message.error('请输入工具名称')
        return
      }
      if (this.ruleForm.application === '01') {
        if (this.ruleForm.usePriority === '') {
          this.$message.error('请输入常用优先级')
          return
        }
      }
      if (this.ruleForm.imageUrlOpen === '') {
        this.$message.error('请上传已开放照片')
        return
      }
      if (this.ruleForm.imageUrlClose === '') {
        this.$message.error('请上传未开放照片')
        return
      }
      // if (this.ruleForm.price === '') {
      //   this.$message.error('请输入价格')
      //   return
      // }
      if (this.ruleForm.application !== '01') {
        if (this.ruleForm.priority === '') {
          this.$message.error('请输入分类优先级')
          return
        }
      }

      if (this.ruleForm.presenterIntegral === '') {
        this.ruleForm.presenterIntegral = 0
      }

      this.$post('/web/tools', { ...this.ruleForm }, 'json').then((res) => {
        if (res.data.code === '0') {
          this.$message.success('新增成功')
          this.dialogVisible = false
          this.ruleForm = {}
          //  this.ruleForm = {}
          this.imageUrl1 = ''
          this.imageUrl2 = ''
          this.search()
        } else {
          this.$message.error(res.data.message)
        }
      })
    },
    submitFormEdit() {
      this.editForm.imageUrlOpen = this.imageUrl1
      this.editForm.imageUrlClose = this.imageUrl2
      if (this.editForm.toolName === '') {
        this.$message.error('请输入工具名称')
        return
      }
      if (this.editForm.imageUrlOpen === '') {
        this.$message.error('请上传已开放照片')
        return
      }
      if (this.editForm.imageUrlClose === '') {
        this.$message.error('请上传未开放照片')
        return
      }
      if (this.editForm.application === '01') {
        if (this.editForm.usePriority === '') {
          this.$message.error('请输入常用优先级')
          return
        }
      }
      if (this.editForm.priority === '') {
        this.$message.error('请输入分类优先级')
        return
      }
      // if (this.editForm.usePriority === '') {
      //   this.$message.error('请输入常用优先级')
      //   return
      // }
      if (this.editForm.presenterIntegral === '') {
        this.editForm.presenterIntegral = 0
      }
      this.$put('/web/tools', { ...this.editForm }, 'json').then((res) => {
        if (res.data.code === '0') {
          this.$message.success('编辑成功')
          this.editdialogVisible = false
          this.ruleForm = {}
          this.search()
        } else {
          this.$message.error(res.data.message)
        }
      })
    },
    reset() {
      this.searchForm = {}
      this.dateTime = ''
      this.search()
      // this.brand()
    },
    handleAvatarSuccess1(res, file) {
      console.log(res)
      this.imageUrl1 = res.data
    },
    handleAvatarSuccess2(res, file) {
      console.log(res)
      this.imageUrl2 = res.data
    },
    back() {
      Object.values(this.ruleForm).forEach((res) => {
        console.log(res)
        if (res === '' || res === 0) {
          this.dialogVisible = false
        } else {
          this.$confirm('即将返回页面,是否要保存内容?', '返回', {
            confirmButtonText: '保存',
            cancelButtonText: '不保存',
            type: 'warning'
          })
            .then(() => {
              this.dialogVisible = false
            })
            .catch(() => {
              this.ruleForm = {}
              this.dialogVisible = false
            })
        }
      })
    },
    edit({ id }) {
      this.$post(
        '/web/operationLog/list',
        {
          queryRequest: {
            pageNum: this.paginations.pageNum,
            pageSize: this.paginations.pageSize,
            field: 'createTime',
            order: 'descending'
          },
          entity: {
            tableName: 'tools',
            columnId: id
          }
        },
        'json'
      ).then((res) => {
        if (res.data.code === '0') {
          this.list1 = res.data.data.records
          this.total2 = res.data.data.total
        }
      })
      this.$get('/web/tools/get', { id }).then((res) => {
        if (res.data.code === '0') {
          this.editdialogVisible = true
          this.editForm = res.data.data
          this.editForm.payType = String(this.editForm.payType)
          this.editForm.status = String(this.editForm.status)
          this.editForm.isUse = String(this.editForm.isUse)
          this.editForm.plusV = String(this.editForm.plusV)
          this.imageUrl1 = this.editForm.imageUrlOpen
          this.imageUrl2 = this.editForm.imageUrlClose
          this.editForm.classifyType = String(this.editForm.classifyType)
        }
        // console.log(res)
      })
    },
    updateStatus({ id, status }) {
      status = status === 1 ? '0' : '1'
      console.log(status)
      const title = status === '0' ? '开放' : '关闭'
      const content =
        status === '0'
          ? '是否确认开放该工具，开放后可使用该工具?'
          : '是否确认关闭该工具，关闭后将不能使用该工具?'
      this.$confirm(content, title, {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$put(
            '/web/tools/updateStatus',
            { entity: { status, id: String(id) }},
            'json'
          ).then((res) => {
            if (res.data.code === '0') {
              this.$message.success('状态修改成功')
              this.search()
            } else {
              this.$message.error(res.data.message)
            }
          })
        })
        .catch(() => {})
    },
    search2(e) {
      if (e && e.page) {
        this.paginations.pageNum = e.page
        this.paginations.pageSize = e.limit
      }
      this.$post(
        '/web/operationLog/list',
        {
          queryRequest: {
            pageNum: this.paginations.pageNum,
            pageSize: this.paginations.pageSize,
            field: 'createTime',
            order: 'descending'
          },
          entity: {
            tableName: 'tools',
            columnId: this.editForm.id
          }
        },
        'json'
      ).then((res) => {
        if (res.data.code === '0') {
          this.list1 = res.data.data.records
          this.total2 = res.data.data.total
        }
      })
    },
    submitFormEdits() {
      this.$confirm('是否确认提交?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          let list = []
          this.priceList.forEach((item, i) => {
            console.log(item)
            if (this.toolName === '车辆检测') {
              if (item.type === 101) {
                list.push({
                  id: item.id,
                  amount: this.priceForm.price,
                  type: item.type,
                  toolId: this.toolId
                })
              } else if (item.type === 102) {
                list.push({
                  id: item.id,
                  amount: `${this.priceForm.price1}`,
                  type: item.type,
                  toolId: this.toolId
                })
              } else if (item.type === 103) {
                list.push({
                  id: item.id,
                  amount: `${this.priceForm.price2}`,
                  type: item.type,
                  toolId: this.toolId
                })
              } else if (item.type === 120) {
                if (this.application !== '00') {
                  list.push({
                    id: item.id,
                    amount: `${this.priceForm.plusVPrice}`,
                    type: item.type,
                    toolId: this.toolId
                  })
                }
              }
            } else if (this.toolName === '维保记录') { // 维保记录
              if (item.type === 100) {
                list.push({
                  id: item.id,
                  amount: this.priceForm.price,
                  type: item.type,
                  toolId: this.toolId
                })
              } else if (item.type === 99) {
                list.push({
                  id: item.id,
                  amount: `${this.priceForm.price4}`,
                  type: item.type,
                  toolId: this.toolId
                })
              } else if (item.type === 120) {
                if (this.application !== '00') {
                  list.push({
                    id: item.id,
                    amount: `${this.priceForm.plusVPrice}`,
                    type: item.type,
                    toolId: this.toolId
                  })
                }
              }
            } else {
              if (item.type === 100) {
                list.push({
                  id: item.id,
                  type: item.type,
                  amount: `${this.priceForm.price}`,
                  toolId: this.toolId
                })
              } else if (item.type === 120) {
                if (this.application !== '00') {
                  list.push({
                    id: item.id,
                    type: item.type,
                    amount: `${this.priceForm.plusVPrice}`,
                    toolId: this.toolId
                  })
                }
              }
            }
          })
          console.log(list)

          if (Number(this.priceForm.plusVPrice) > 9999999.99) {
            return this.$message.error('金额应小于9999999.99')
          }
          if (this.priceList.length !== 0) {
            this.$put('/web/toolsAmount', list, 'json').then((res) => {
              if (res.data.code === '0') {
                this.editPricedialogVisible = false
                this.$message.success('价格设置成功')
              } else {
                this.$message.error(res.data.message)
              }
            })
          } else {
            // 新增
            if (this.application !== '00') {
              list = [
                {
                  toolId: this.toolId,
                  type: 100,
                  amount: this.priceForm.price
                }, {
                  toolId: this.toolId,
                  type: 120,
                  amount: this.priceForm.plusVPrice
                }
              ]
            } else {
              list = [
                {
                  toolId: this.toolId,
                  type: 100,
                  amount: this.priceForm.price
                }
              ]
            }

            if (this.toolName === '车辆检测') {
              list = [
                {
                  toolId: this.toolId,
                  type: 101,
                  amount: this.priceForm.price
                },
                {
                  toolId: this.toolId,
                  type: 102,
                  amount: this.priceForm.price1
                },
                {
                  toolId: this.toolId,
                  type: 103,
                  amount: this.priceForm.price2
                }
              ]
            }
            if (this.toolName === '维保记录') {
              list = [
                {
                  toolId: this.toolId,
                  type: 100,
                  amount: this.priceForm.price
                }, {
                  toolId: this.toolId,
                  type: 99,
                  amount: this.priceForm.price4
                }
              ]
            }
            this.$post('/web/toolsAmount', list, 'json').then((res) => {
              if (res.data.code === '0') {
                this.editPricedialogVisible = false
                this.$message.success('价格设置成功')
              } else {
                this.$message.error(res.data.message)
              }
            })
          }
        })
        .catch(() => {})
    }
  }
}
</script>

<style lang="scss" scoped>
.myeditForm {
  th {
    height: 40px;
    line-height: 40px;
  }
  th,
  td {
    border: 1px solid #d9d9d9;
  }
  table {
    margin-bottom: 20px;
  }
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  margin-left: 10px;

  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 80px;
  height: 80px;
  line-height: 80px;
  text-align: center;
}
.avatar {
  width: 80px;
  height: 80px;
  display: block;
}
</style>
